import xlrd
from datetime import datetime


class ReadExcel(object):
    def __init__(self, data_path, sheetname ):
        #定义一个属性接收文件路径
        self.data_path = data_path
        # 定义一个属性接收工作表名称
        self.sheetname = sheetname
        # 使用xlrd模块打开excel表读取数据
        self.data = xlrd.open_workbook(self.data_path)
        # 根据工作表的名称获取工作表中的内容
        self.table = self.data.sheet_by_name(self.sheetname)
        # 获取工作表的有效行数
        self.rowNum = self.table.nrows


    def readExcel(self):
        for i in range(1, self.rowNum):
            # 获取单元格数据
            asrIntentTime = int(self.table.cell_value(i, 3))
            endTime = self.table.cell_value(i, 5)
            dt = datetime.strptime(endTime, "%Y/%m/%d %H:%M:%S")
            timestamp = int(dt.timestamp()) * 1000

            print(timestamp-asrIntentTime)
            # print(contents)


if __name__ == '__main__':
    datapath = '/Users/v_baiguanghui/Desktop/数据分析-11.9.xlsx'
    sheetname = '时延统计'
    obj = ReadExcel(datapath,sheetname)
    obj.readExcel()